
/**
 * UI服务注册中心
 *
 * @export
 * @class UIServiceRegister
 */
export class UIServiceRegister {

    /**
     * UIServiceRegister 单例对象
     *
     * @private
     * @static
     * @memberof UIServiceRegister
     */
    private static UIServiceRegister:UIServiceRegister;

    /**
     * 所有UIService Map对象
     *
     * @private
     * @static
     * @memberof UIServiceRegister
     */    
    private static allUIServiceMap:Map<string,any> = new Map();

    /**
     * Creates an instance of UIServiceRegister.
     * @memberof UIServiceRegister
     */
    constructor() {
        this.init();
    }

    /**
     * 获取UIServiceRegister 单例对象
     *
     * @public
     * @static
     * @memberof UIServiceRegister
     */
    public static getInstance(){
        if(!this.UIServiceRegister){
            this.UIServiceRegister = new UIServiceRegister();
        }
        return this.UIServiceRegister;
    }

    /**
     * 初始化
     *
     * @protected
     * @memberof UIServiceRegister
     */
    protected init(): void {
                UIServiceRegister.allUIServiceMap.set('orderdetails', () => import('../uiservice/orderdetails/orderdetails-ui-service'));
        UIServiceRegister.allUIServiceMap.set('order1', () => import('../uiservice/order1/order1-ui-service'));
        UIServiceRegister.allUIServiceMap.set('pcmap', () => import('../uiservice/pcmap/pcmap-ui-service'));
        UIServiceRegister.allUIServiceMap.set('saleplatform', () => import('../uiservice/saleplatform/saleplatform-ui-service'));
        UIServiceRegister.allUIServiceMap.set('chartentity', () => import('../uiservice/chartentity/chartentity-ui-service'));
        UIServiceRegister.allUIServiceMap.set('customer', () => import('../uiservice/customer/customer-ui-service'));
        UIServiceRegister.allUIServiceMap.set('dynamicentity', () => import('../uiservice/dynamic-entity/dynamic-entity-ui-service'));
        UIServiceRegister.allUIServiceMap.set('majorentity', () => import('../uiservice/majorentity/majorentity-ui-service'));
        UIServiceRegister.allUIServiceMap.set('orderdetail', () => import('../uiservice/orderdetail/orderdetail-ui-service'));
    }

    /**
     * 获取指定UIService
     *
     * @public
     * @memberof UIServiceRegister
     */
    public async getService(context:any,entityKey:string){
        const importService = UIServiceRegister.allUIServiceMap.get(entityKey);
        if(importService){
            const importModule = await importService();
            return importModule.default.getInstance(context);
        }
    }

}